package com.zoro.barn.business.service.login.business.normalpassword.util.token;

import java.util.*;

/**
 * @author zhaoxingwu
 */
public class TokenPayload extends AbstractMap<String, Object> {
    private final Map<String, Object> claimMap = new HashMap<>();


    private TokenPayload() {
    }

    private TokenPayload(Map<String, Object> claimMap) {
        this.claimMap.putAll(claimMap);
    }

    public String getIss() {

        Object iss = this.get("iss");
        if (iss instanceof String) {
            return (String) iss;
        } else {
            return null;
        }

    }

    public long getExp() {
        Object exp = this.get("exp");
        if (exp instanceof Long) {
            return (long) exp;
        } else {
            return 0;
        }
    }

    public String getSub() {
        Object sub = this.get("sub");
        if (sub instanceof String) {
            return (String) sub;
        } else {
            return null;
        }
    }

    public String getAud() {
        Object aud = this.get("aud");
        if (aud instanceof String) {
            return (String) aud;
        } else {
            return null;
        }
    }

    public long getNbf() {
        Object nbf = this.get("nbf");
        if (nbf instanceof Long) {
            return (long) nbf;
        } else {
            return 0;
        }
    }

    public long getIat() {
        Object iaf = this.get("iaf");
        if (iaf instanceof Long) {
            return (long) iaf;
        } else {
            return 0;
        }
    }

    public String getJti() {
        Object jti = this.get("jti");
        if (jti instanceof String) {
            return (String) jti;
        } else {
            return null;
        }
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        return claimMap.entrySet();
    }

    @Override
    public int size() {
        return claimMap.size();
    }

    @Override
    public boolean isEmpty() {
        return claimMap.isEmpty();
    }

    @Override
    public boolean containsValue(Object value) {
        return claimMap.containsValue(value);
    }

    @Override
    public boolean containsKey(Object key) {
        return claimMap.containsKey(key);
    }

    @Override
    public Object get(Object key) {
        return claimMap.get(key);
    }

    @Override
    public Object put(String key, Object value) {
        return claimMap.put(key, value);
    }

    @Override
    public Object remove(Object key) {
        return claimMap.remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ?> m) {
        claimMap.putAll(m);
    }

    @Override
    public void clear() {
        claimMap.clear();
    }

    @Override
    public Set<String> keySet() {
        return claimMap.keySet();
    }

    @Override
    public Collection<Object> values() {
        return claimMap.values();
    }

    @Override
    public boolean equals(Object o) {
        return claimMap.equals(o);
    }

    @Override
    public int hashCode() {
        return claimMap.hashCode();
    }

    @Override
    public String toString() {
        return claimMap.toString();
    }

    public static TokenPayloadBuilder builder() {
        return new TokenPayloadBuilder(new TokenPayload());
    }

    public static TokenPayload from(Map<String, Object> source) {
        return new TokenPayload(source);
    }


}
